package com.qf.agro.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.qf.agro.common.SysUserHolder;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @author 10202
 * @version V1.0
 * @Project smart-agriculture-parent
 * @Package com.qf.agro.config
 * @Date 2023/7/3 19:28
 */
@Component
public class MyMetaObjecthandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        metaObject.setValue("createTime", LocalDateTime.now());
        metaObject.setValue("updateTime", LocalDateTime.now());
        metaObject.setValue("companyId", SysUserHolder.get().getCompanyId());
        metaObject.setValue("companyName",SysUserHolder.get().getCompanyName());

    }
    @Override
    public void updateFill(MetaObject metaObject) {
        metaObject.setValue("updateTime", LocalDateTime.now());

        if(SysUserHolder.get()!=null){
            metaObject.setValue("updateBy",SysUserHolder.get().getId());
        }
    }
}
